home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / util / sys / 68040lib.lha / 68040Lib / Install / ScanToConfig.rexx < prev    next >
OS/2 REXX Batch file  |  2000-03-29  |  14KB  |  367 lines

  1. /*********************************************************
  2.  ** ScanToConfig                                          **
  3.  **                                                     **
  4.  ** Builds the MMU-Configuration file automatically     **
  5.  ** from the MuScan output, including kludges for      **
  6.  ** bad or mis-designed hardware                        **
  7.  ** Version 1.03 © 2000 THOR-Software, Thomas Richter   **
  8.  ** 28.03.2000                                          **
  9.  *********************************************************/
  10.  
  11. PARSE ARG destination .
  12.  
  13.         if (destination = '') then
  14.                 destination = '*'
  15.  
  16.         
  17.         rec = 25;
  18.  
  19.         if (OPEN(.out,destination,'W')) THEN; DO
  20.                 rv=WRITELN(.out,";*************************************************************************");
  21.                 rv=WRITELN(.out,";** MMU Configuration file                                              **");
  22.                 rv=WRITELN(.out,";**                                                                     **");
  23.                 rv=WRITELN(.out,";** this file is read on startup by the mmu.library and used to modify  **");
  24.                 rv=WRITELN(.out,";** the pre-calculated or scanned MMU table                             **");
  25.                 rv=WRITELN(.out,";**                                                                     **");
  26.                 rv=WRITELN(.out,";** © 1999,2000 THOR Software, Thomas Richter                           **");
  27.                 rv=WRITELN(.out,";*************************************************************************");
  28.                 rv=WRITELN(.out,"");
  29.                 rv=WRITELN(.out,"");
  30.                 rv=WRITELN(.out,"");
  31.                 rv=WRITELN(.out,"; the current version of the MMU library knows four commands that can");
  32.                 rv=WRITELN(.out,"; be used in this file:");
  33.                 rv=WRITELN(.out,"; CLEARTTX clears all or parts of the transparent translation registers");
  34.                 rv=WRITELN(.out,"; ADDMEM   adds memory to the exec free list pool. BE WARNED, this command");
  35.                 rv=WRITELN(.out,";          does NOT modify the MMU tables, this must be done manually with");
  36.                 rv=WRITELN(.out,";          SETCACHEMODE");
  37.                 rv=WRITELN(.out,"; SETCACHEMODE  defines the MMU tables.");
  38.                 rv=WRITELN(.out,"; DESCRIPTORCACHEINHIBIT defines whether the data cache should be disabled");
  39.                 rv=WRITELN(.out,"; for the MMU descriptors. It's usually OFF meaning the cache will remain");
  40.                 rv=WRITELN(.out,"; enabled. This is fine for the mmu.library, but certain hacks might require");
  41.                 rv=WRITELN(.out,"; an ON argument here. Note that this means more work for the library.");
  42.                 rv=WRITELN(.out,"");
  43.                 rv=WRITELN(.out,"");
  44.                 rv=WRITELN(.out,"ClearTTx        ;ignore all TTX registers if any. We don't need them");
  45.                 rv=WRITELN(.out,"");
  46.                 rv=WRITELN(.out,";DescriptorCacheInhibit ON     ;make access to MMU descriptors cache inhibited");              
  47.                 rv=WRITELN(.out,"");
  48.                 rv=WRITELN(.out,"");
  49.                 rv=WRITELN(.out,";Board specific setup follows here,");
  50.                 rv=WRITELN(.out,";generated by ScanToConfig 1.03 © 28.03.2000 THOR-Software");
  51.                 rv=WRITELN(.out,"");
  52.  
  53.         rv=WRITELN(.out,";General memory setup follows.");
  54.         rv=WRITELN(.out,";The following lines are a compatibility kludge for some P5 boards");
  55.         rv=WRITELN(.out,";which enable the MMU prior to the 68040/68060 library and leave");
  56.         rv=WRITELN(.out,";the memory in CACHEINHIBIT state. You may remove the following");
  57.         rv=WRITELN(.out,";lines on all other machines most likely.");
  58.         rv=WRITELN(.out,"");
  59.  
  60.         ADDRESS COMMAND "MemModes >T:MemInfo";
  61.         IF (OPEN(.meminfo,"T:MemInfo",'R')) THEN; DO 
  62.             DO UNTIL EOF(.meminfo)
  63.                 line = READLN(.meminfo);
  64.                 WRITELN(.out,line);
  65.             END;
  66.             rv=CLOSE(.meminfo);
  67.         END;
  68.         
  69.         rv=WRITELN(.out,";Memory setup end.");
  70.         rv=WRITELN(.out,"");
  71.         rv=WRITELN(.out,"");
  72.  
  73.         ADDRESS COMMAND 'FindPort "BOOT-MMU-Port"'
  74.         portmode = RC;
  75.  
  76.         ADDRESS COMMAND "ShowBoards to T:BoardInfo";
  77.         boards = 0;
  78.         if (OPEN(.boardinfo,"T:BoardInfo",'R')) then; do
  79.             DO UNTIL EOF(.boardinfo)
  80.                 line = READLN(.boardinfo)
  81.                 IF line ~= '' THEN; DO
  82.                     PARSE VAR line 'Type:' type 'Product:' product 'Manufacturer:' mf 'Serial#:' id 'BoardAddr:' from 'BoardSize:' size;
  83.                     boards = boards + 1;
  84.                     type.boards=X2D(type);
  85.                     product.boards=X2D(product);
  86.                     mf.boards=X2D(mf);
  87.                     id.boards=X2D(id);
  88.                     base.boards=X2D(SUBSTR(from,2,6));
  89.                     end.boards=X2D(SUBSTR(size,2,6))+base.boards;
  90.                 END
  91.             END    
  92.             rv=CLOSE(.boardinfo);
  93.         END
  94.         ADDRESS COMMAND "MuScan to T:BoardInfo";
  95.                 if (OPEN(.boardinfo,"T:BoardInfo",'R')) then; do
  96.                         rec = 0;
  97.             scan = 0;
  98.             portwarn = 0;
  99.             ppcwarn = 0;
  100.                         DO UNTIL EOF(.boardinfo)
  101.                                 line = READLN(.boardinfo)
  102.                 IF scan = 0 THEN; DO
  103.                     IF line = 'Memory map:' THEN; DO
  104.                         scan = 1;
  105.                     END;
  106.                 END; ELSE; DO
  107.                     IF line ~= '' THEN; DO
  108.                         base = SUBWORD(line,1,1);
  109.                         end  = SUBWORD(line,3,1);
  110.                         mode = SUBWORD(line,4);
  111.                         rv   = ScanEntry(base,end,mode);    
  112.                     END;
  113.                 END
  114.             END
  115.                         rv=CLOSE(.boardinfo);
  116.                 END
  117.  
  118.         /* P5 setup kludges follow here..... Sigh */
  119.  
  120.         romlibs        = 0;            /* libs in ROM? */
  121.  
  122.         ADDRESS COMMAND 'P5Identify'
  123.         p5mode         = RC;            /* Possibly P5 board? */
  124.         ADDRESS COMMAND 'FindPort "BOOT-MMU-Port"'
  125.         portmode     = RC;            /* MMU setup kludge? */
  126.         ADDRESS COMMAND 'FindResident "ppc.library"'
  127.         ppclibmode     = RC;            /* PPCLib in ROM? */
  128.         ADDRESS COMMAND 'FindResident "68060quick.library"'
  129.         quicklibmode     = RC;            /* quick lib in ROM? */
  130.         ADDRESS COMMAND 'FindResident "68060.library"'
  131.         libmode     = RC;            /* 060 lib in ROM? */
  132.         ADDRESS COMMAND 'FindResident "68040.library"'
  133.         lib4mode     = RC;            /* 040 lib in ROM? */
  134.  
  135.         IF p5mode ~= 0 THEN; DO
  136.             p5init         = 1
  137.             ppccheck    = 1
  138.         END;
  139.         
  140.         IF ppclibmode = 0 THEN; DO
  141.             ppccheck    = 1
  142.         END;
  143.  
  144.         IF portmode = 0 THEN; DO
  145.             ppccheck     = 1
  146.             p5init         = 1
  147.         END;
  148.  
  149.         IF (quicklibmode = 0) | (libmode = 0) | (lib4mode = 0) | (ppclibmode = 0) THEN; DO
  150.             p5init         = 1
  151.             romlibs        = 1
  152.             ppccheck    = 1
  153.         END;
  154.  
  155.         IF p5init = 1 THEN;DO
  156.             rv=WRITELN(.out,"");
  157.             rv=WRITELN(.out,";P5 fixes follow here:");
  158.             rv=WRITELN(.out,";If you do not own a P5 board, you may remove the following lines");
  159.             rv=WRITELN(.out,";");
  160.             rv=WRITELN(.out,";Several P5 boards build a private MMU setup on boot");
  161.             rv=WRITELN(.out,";using a kludge called the BOOT-MMU-Port. To run this");
  162.             rv=WRITELN(.out,";kludge, the following external command is run from");
  163.             rv=WRITELN(.out,";LIBS:mmu/ as all other external commands");
  164.             rv=WRITELN(.out,";");
  165.             rv=WRITELN(.out,";This command installs also other P5 relevant MMU settings");
  166.             rv=WRITELN(.out,";Hence, for P5 boards, please keep it in place even if");
  167.             rv=WRITELN(.out,";you *DO NOT* see the BOOT-MMU-Port.");
  168.             rv=WRITELN(.out,";");
  169.             IF ~EXISTS("LIBS:mmu") THEN; DO
  170.                 OPTIONS FAILAT 15
  171.                 ADDRESS COMMAND 'MakeDir >NIL: LIBS:MMU'
  172.                 OPTIONS FAILAT 10
  173.             END;
  174.             IF ~EXISTS("LIBS:mmu/P5Init") THEN; DO
  175.                 ADDRESS COMMAND 'Copy >NIL: P5Init to LIBS:MMU/P5Init'
  176.             END;
  177.             rv=WRITELN(.out,"P5Init");
  178.             rv=WRITELN(.out,"");
  179.             rv=WRITELN(.out,"");
  180.         END;            
  181.  
  182.         IF ppccheck = 1 THEN; DO
  183.             ADDRESS COMMAND 'PPCIdentify'
  184.             ppccheck = RC;
  185.         END;
  186.  
  187.         IF ppccheck = 1 THEN; DO
  188.             SAY "The setup script found a P5 board with PPC processor.";
  189.             SAY "While not a problem in general, please note that you";
  190.             SAY "absolutely *MUST NOT* use the ppc.library together";
  191.             SAY "with the mmu.library. This won't work.";
  192.         END;
  193.  
  194.         IF romlibs = 1 THEN; DO
  195.             rv=WRITELN(.out,"");
  196.             rv=WRITELN(.out,";This board has some processor libs resident");
  197.             rv=WRITELN(.out,";BPPCFix should be run to remove it.");
  198.             rv=WRITELN(.out,";This command has been installed into C:");
  199.             rv=WRITELN(.out,";by the setup script.");
  200.             SAY "The setup script found some processor libraries resident in ROM";
  201.             SAY "You will not be able to use the MuLib specific processor";
  202.             SAY "libraries unless you run BPPCFix in your startup-sequence.";
  203.             SAY "Please study the BPPCFix manual for details on how to run";
  204.             SAY "this program to replace the ROM-based libraries."
  205.             SAY "";
  206.             SAY "";
  207.             SAY "Note further that you *DO NOT* need the ENVARC:MMU-Configuration"
  208.             SAY "file if you continue to use the ROM resident libraries.";
  209.             SAY "";
  210.             IF ~EXISTS("C:BPPCFix") THEN; DO
  211.                 ADDRESS COMMAND 'Copy >NIL: BPPCFix to C:BPPCFix'
  212.                 SAY "Copied BPPCFix to C: for convenience...";
  213.             END;
  214.         END;
  215.  
  216.         rv=WRITELN(.out,"");
  217.         rv=CLOSE(.out);
  218.         ADDRESS COMMAND 'Delete T:BoardInfo QUIET'
  219.     END    
  220.  
  221. RETURN 0
  222.  
  223.  
  224. ScanEntry:
  225. PARSE ARG base,end,mode
  226.  
  227.     base = X2D(SUBSTR(base,3,6))
  228.     end  = X2D(SUBSTR(end,3,6))+1
  229.  
  230.     copyback     =    INDEX(mode,'CopyBack')>0;
  231.     cacheinhibit    =    INDEX(mode,'CacheInhibit')>0;
  232.     invalid        =    INDEX(mode,'Blank')>0 | INDEX(mode,'Invalid')>0;
  233.     remapped    =    INDEX(mode,'Remapped')>0;
  234.     speedup        =    INDEX(mode,'NonSerial')>0 | INDEX(mode,'Imprecise')>0;
  235.     iomark        =    0;
  236.     board        =    0;
  237.  
  238.     DO i=1 TO boards
  239.         IF base<end.i & end>base.i THEN; DO
  240.             iomark = 1;    
  241.         END;
  242.     END;
  243.     
  244.     cachemodes    =    "WriteThrough";
  245.     iomodes        =    "";
  246.     IF copyback    THEN    cachemodes="CopyBack";
  247.     IF cacheinhibit    THEN    cachemodes="CacheInhibit";
  248.     IF speedup    THEN    cachemodes="CacheInhibit Imprecise NonSerial";
  249.     IF iomark    THEN    iomodes="IOSpace";
  250.  
  251.     memrange = "SetCacheMode 0x"D2X(base)"00 Size 0x"D2X(end-base)"00";
  252.  
  253.     zeropage    =    0;
  254.     chipmem        =    0;
  255.     zorro2        =    0;
  256.     iospace        =    0;
  257.     mother        =    0;
  258.     rangermem    =    0;
  259.     p5space        =    0;
  260.     ppcspace    =    0;
  261.     mem        =    0;
  262.     rom        =    0;
  263.  
  264.     IF end<=X2D('80')                 THEN zeropage    = 1;
  265.     IF end<=X2D('2000')                THEN chipmem    = 1;
  266.     IF base>=X2D('2000')    & end<=X2D('A000')    THEN zorro2    = 1;
  267.     IF base>=X2D('A000')    & end<=X2D('B800')    THEN iospace    = 1;
  268.     IF base>=X2D('B800')    & end<=X2D('C000')    THEN mother    = 1;
  269.     IF base>=X2D('C000')    & end<=X2D('D800')    THEN rangermem    = 1;
  270.     IF base>=X2D('DA00')    & end<=X2D('E000')    THEN mother    = 1;
  271.     IF base>=X2D('E800')    & end<=X2D('F000')    THEN iospace    = 1;
  272.     IF base>=X2D('F000')    & end<=X2D('F800')    THEN p5space    = 1;
  273.     IF base>=X2D('F800')    & end<=X2D('10000')    THEN rom    = 1;
  274.     IF base>=X2D('10000')    & end<=X2D('100000')    THEN mem    = 1;
  275.     IF base>=X2D('80000')    & end<=X2D('100000')    THEN ppcspace    = 1;
  276.     IF base>=X2D('100000')    & end<=X2D('800000')    THEN iospace    = 1;
  277.     IF base>=X2D('400000')    & end<=X2D('C00000')    THEN ppcspace    = 1;
  278.     IF base>=X2D('E00000')    & end<=X2D('1000000')    THEN p5space    = 1;
  279.     IF base>=X2D('FF0000')    & end<=X2D('FF1000')    THEN iospace    = 1;
  280.     IF iomark                    THEN iospace    = 1;
  281.     
  282.     /* found remapped chip memory */
  283.     IF zeropage & remapped THEN; DO
  284.         SAY 'Found a remapped ZeroPage, it might be a good idea to run MuFastZero.';
  285.         SAY 'If MuFastZero fails with "Zero page already remapped", please add the';
  286.         SAY 'FORCENATIVE command line option.';
  287.       END;
  288.  
  289.     /* found fast chip. This can be turned on in either case */
  290.     IF chipmem & (~remapped) & (~invalid) THEN; DO
  291.         rv=WRITELN(.out,";In case you don't run the V40 68040 resp. 68060.library");
  292.         rv=WRITELN(.out,";the following line will speed up the chip memory. It is");
  293.         rv=WRITELN(.out,";not required otherwise.");
  294.         rv=WRITELN(.out,memrange "CacheInhibit Imprecise NonSerial");
  295.                   rv=WRITELN(.out,"");
  296.     END;
  297.  
  298.     /* found slow zorro II or gfx mem? */
  299.     IF zorro2 & (~copyback) & (~invalid) & (~iomark) THEN; DO
  300.         rv=WRITELN(.out,";Found slow Zorro-II memory. Keeping the caches disabled.");
  301.         rv=WRITELN(.out,memrange "CacheInhibit Imprecise NonSerial Valid");
  302.         rv=WRITELN(.out,"");
  303.     END;
  304.  
  305.     /* copy attributes for the IO space */
  306.     IF iospace & (~invalid) & (~remapped) THEN; DO
  307.         rv=WRITELN(.out,memrange cachemodes "Valid IOSpace");
  308.         rv=WRITELN(.out,"");
  309.     END;
  310.  
  311.     /* setup ranger memory */
  312.     IF rangermem & (~invalid) & (~remapped) THEN; DO
  313.         rv=WRITELN(.out,memrange "CacheInhibit Imprecise NonSerial Valid");
  314.         rv=WRITELN(.out,"");
  315.     END;
  316.  
  317.     /* setup P5 uglyness */
  318.     IF p5space & (~invalid) & (~remapped) & (~iospace) THEN; DO
  319.         rv=WRITELN(.out,";The following memory region should be left blank");
  320.         rv=WRITELN(.out,";according to the CBM design rules. It isn't...");
  321.         rv=WRITELN(.out,memrange cachemodes "Valid IOSpace");
  322.         rv=WRITELN(.out,"");
  323.     END;
  324.  
  325.     /* found remapped ROM? */
  326.     IF rom & remapped THEN; DO
  327.         SAY 'Found a remapped ROM, running MuFastRom might be a good idea,';
  328.         SAY 'but make sure you disable other ROM remappers before trying';
  329.         SAY 'to use the MMU.library setup.';
  330.     END;
  331.  
  332.     /* strange caching modes in RAM? */
  333.     IF mem THEN; DO
  334.         IF ~copyback THEN; DO
  335.             IF ~portwarn THEN; DO
  336.                 SAY 'WARNING! Found non-copyback memory regions.';
  337.                 SAY 'This could mean that either the ppc.library is running';
  338.                 SAY 'or P5 I/O hardware is active.';
  339.                 SAY 'For the time being, I do nothing about it, but you should';
  340.                 SAY 'check the MMU-Configuration file manually and follow the';
  341.                 SAY 'notes in this file for further testing.';
  342.                 rv=WRITELN(.out,"WARNING! Found non-copyback memory regions.");
  343.                 rv=WRITELN(.out,"This could mean that either the ppc.library is running");
  344.                 rv=WRITELN(.out,"or P5 I/O hardware is active.");
  345.                 rv=WRITELN(.out,"For the time being, I do nothing about it, but you could");
  346.                 rv=WRITELN(.out,"try to remove the semi-colon for the following lines:");
  347.                 portwarn = 1;
  348.             END;
  349.             rv=WRITELN(.out,";"memrange cachemodes "Valid");
  350.         END;
  351.     END;
  352.  
  353.     /* PPC memory area marked as valid? */
  354.     IF ppcspace & (~invalid) & (~remapped) THEN; DO
  355.         IF ~ppcwarn THEN; DO
  356.             SAY 'WARNING! Found possible PPC memory regions.';
  357.             SAY 'DO NOT RUN THE ppc.library or you get problems.';
  358.             ppcwarn = 1;
  359.         END;
  360.         rv=WRITELN(.out,";If you don't own a PPC, you may remove the next line:");
  361.         rv=WRITELN(.out,memrange cachemodes iomodes "Valid");
  362.         rv=WRITELN(.out,"");
  363.     END;
  364.  
  365.  
  366. RETURN 0
  367.